home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Magazine / UsingPDF / GhostScript / source / gs5.10 / icontext.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-26  |  3.6 KB  |  118 lines

  1. /* Copyright (C) 1997 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* icontext.c */
  20. /* Context state operations */
  21. #include "ghost.h"
  22. #include "gsstruct.h"        /* for gxalloc.h */
  23. #include "gxalloc.h"
  24. #include "errors.h"
  25. #include "igstate.h"
  26. #include "icontext.h"
  27. #include "interp.h"
  28. #include "dstack.h"
  29. #include "estack.h"
  30. #include "ostack.h"
  31. #include "store.h"
  32.  
  33. /* Define the initial stack sizes. */
  34. #define DSTACK_INITIAL 20
  35. #define ESTACK_INITIAL 250
  36. #define OSTACK_INITIAL 200
  37.  
  38. /* Per-context state stored in statics */
  39. extern ref ref_array_packing;
  40. extern ref ref_binary_object_format;
  41. extern ref user_names;
  42. extern long zrand_state;
  43.  
  44. /* Initialization procedures */
  45. void zrand_state_init(P1(long *));
  46.  
  47. /* Allocate the state of a context. */
  48. /* The client is responsible for the 'memory' member. */
  49. int
  50. context_state_alloc(gs_context_state_t *pcst, gs_ref_memory_t *mem)
  51. {    int code = gs_interp_create_stacks(mem, &pcst->dstack, &pcst->estack,
  52.                        &pcst->ostack);
  53.  
  54.     if ( code < 0 )
  55.       return code;
  56.     pcst->pgs = int_gstate_alloc(mem);
  57.     if ( pcst->pgs == 0 )
  58.       return_error(e_VMerror);
  59.     make_false(&pcst->array_packing);
  60.     make_int(&pcst->binary_object_format, 0);
  61.     zrand_state_init(&pcst->rand_state);
  62.     pcst->usertime_total = 0;
  63.     pcst->keep_usertime = false;
  64.     /****** user parameters ******/
  65.     /****** %stdin, %stdout ******/
  66.     return 0;
  67. }
  68.  
  69. /* Load the interpreter state from a context. */
  70. void
  71. context_state_load(const gs_context_state_t *pcst)
  72. {    d_stack = *r_ptr(&pcst->dstack, ref_stack);
  73.     e_stack = *r_ptr(&pcst->estack, ref_stack);
  74.     o_stack = *r_ptr(&pcst->ostack, ref_stack);
  75.     igs = pcst->pgs;
  76.     gs_imemory = pcst->memory;
  77.     ref_array_packing = pcst->array_packing;
  78.     ref_binary_object_format = pcst->binary_object_format;
  79.     zrand_state = pcst->rand_state;
  80.     /****** user parameters ******/
  81.     /****** %stdin, %stdout ******/
  82. }
  83.  
  84. /* Store the interpreter state in a context. */
  85. void
  86. context_state_store(gs_context_state_t *pcst)
  87. {    *r_ptr(&pcst->dstack, ref_stack) = d_stack;
  88.     *r_ptr(&pcst->estack, ref_stack) = e_stack;
  89.     *r_ptr(&pcst->ostack, ref_stack) = o_stack;
  90.     pcst->pgs = igs;
  91.     pcst->memory = gs_imemory;
  92.     pcst->array_packing = ref_array_packing;
  93.     pcst->binary_object_format = ref_binary_object_format;
  94.     pcst->rand_state = zrand_state;
  95.     /****** user parameters ******/
  96.     /****** %stdin, %stdout ******/
  97. }
  98.  
  99. /* Free the state of a context. */
  100. void
  101. context_state_free(gs_context_state_t *pcst, gs_ref_memory_t *mem)
  102. {    /****** SEE alloc ABOVE ******/
  103.     int i;
  104.  
  105.     /*
  106.      * If this context is the last one referencing a particular VM
  107.      * (local, or local and global), free the entire VM space;
  108.      * otherwise, just free the context-related structures.
  109.      */
  110.     for ( i = countof(pcst->memory.spaces.indexed); --i >= 0; ) {
  111.       if ( pcst->memory.spaces.indexed[i] != 0 &&
  112.            !--(pcst->memory.spaces.indexed[i]->num_contexts)
  113.          ) {
  114.         /****** FREE THE ENTIRE SPACE ******/
  115.       }
  116.     }
  117. }
  118.